import {mediaPhyApi} from './api.js'
import {MD5} from 'libs/crypto.js'

export function getMultiScreenOfLcd(devModel) {
  var x = 1
  var y = 1
  if (devModel.includes('lcdwall')) {
    let multis = devModel.split('.')[2]
    x = parseInt(multis[0] + multis[1])
    y = parseInt(multis[2] + multis[3])       
  }

  return {
    x,
    y
  }
}

export function loadLcdLayoutByName(topoIdOfLcd, name) {
  var paramlist = {
    name: name
  }

  mediaPhyApi.setDevId(topoIdOfLcd)
  return mediaPhyApi.sendCmd('loadLayoutByName', paramlist) 
}

export function saveLcdLayoutByName(topoIdOfLcd, name) {
  var paramlist = {
    name: name
  }

  mediaPhyApi.setDevId(topoIdOfLcd)
  return mediaPhyApi.sendCmd('saveLayoutByName', paramlist) 
}

export function setLcdWindows(topoIdOfLcd, multiScreenX, multiScreenY, windows) {
  var paramlist = {
    multiScreenX,
    multiScreenY,
    windowList: windows
  }

  mediaPhyApi.setDevId(topoIdOfLcd)
  return mediaPhyApi.sendCmd('setLayout', paramlist) 
}

export function encryptPassword(plaintext) {
  let ciphertext = MD5(plaintext).toLowerCase()
  return 'md5#' + ciphertext  
}